﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.Entities;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class ListEstadisticoDAL : DBController
    {
        public ListEstadisticoDAL()
        { 
        
        }

        public List<ListGiftCardsEntity> ListGiftCards(DateTime fechaInicio, DateTime fechaFin)
        {
            try
            {
                List<ListGiftCardsEntity> listado = new List<ListGiftCardsEntity>();
                using (SqlConnection conn = this.OpenConn())
                {

                    SqlDataReader dr;

                    SqlCommand dCmd = new SqlCommand("MARAVILLA_SQL.spListGiftCards", conn);

                    dCmd.CommandText = "MARAVILLA_SQL.spListGiftCards";

                    dCmd.CommandType = CommandType.StoredProcedure;
                    dCmd.Parameters.AddWithValue("@fechaInicio", fechaInicio);
                    dCmd.Parameters.AddWithValue("@fechaFin", fechaFin);


                    // dCmd.ExecuteNonQuery();
                    dr = dCmd.ExecuteReader();
                    dCmd.Dispose();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            ListGiftCardsEntity item = new ListGiftCardsEntity();
                            item.DNI = long.Parse(dr["bigDNI"].ToString());
                            item.ID = Convert.ToInt32(dr["intIdClienteDestino"]);
                            item.SUMA = float.Parse(dr["SUMA"].ToString());
                            item.Nombre = dr["varNombre"].ToString();
                            item.Apellido = dr["varApellido"].ToString();

                            listado.Add(item);
                        }
                    }
                }
                return listado;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public List<ListDevolucionesEntity> ListDevoluciones(DateTime fechaInicio, DateTime fechaFin)
        {
            try
            {
                List<ListDevolucionesEntity> listado = new List<ListDevolucionesEntity>();
                using (SqlConnection conn = this.OpenConn())
                {

                    SqlDataReader dr;

                    SqlCommand dCmd = new SqlCommand("MARAVILLA_SQL.spListDevoluciones", conn);

                    dCmd.CommandText = "MARAVILLA_SQL.spListDevoluciones";

                    dCmd.CommandType = CommandType.StoredProcedure;
                    dCmd.Parameters.AddWithValue("@fechaInicio", fechaInicio);
                    dCmd.Parameters.AddWithValue("@fechaFin", fechaFin);


                    // dCmd.ExecuteNonQuery();
                    dr = dCmd.ExecuteReader();
                    dCmd.Dispose();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            ListDevolucionesEntity item = new ListDevolucionesEntity();
                            item.CUIT = dr["varCUIT"].ToString();
                            item.ID = int.Parse(dr["intIdProveedor"].ToString());
                            item.TOTAL = float.Parse(dr["TOTAL"].ToString());
                            item.RS = dr["varRS"].ToString();

                            listado.Add(item);
                        }
                    }
                }
                return listado;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
